
<?php
date_default_timezone_set('UTC');

$username="bsc353_4";
$password="sonbeans";
$database="bsc353_4";



$date=date("Y-m-d H:i:s"); 
$ISBN=$_POST['ISBN'];
$quantity= intval($_POST['quantity']);
$branch=$_POST['branch'];
$publisher=$_POST['publisher'];
$customerid=$_POST['customerid'];
$branchid=$_POST['branchid'];


if($customerid=="Select One"||$branchid=="Select One" ||$publisher=="Select One"||$branch=="Select One")
{
    echo "Error. Please enter both the Customer ID and Branch ID";
}

else
{

mysql_connect("clipper.encs.concordia.ca",$username,$password) or die ("Unable to connect to database");

@mysql_select_db($database) or die ("Unable to select database");

$orderquery= "Select max(orderNumber) from Orders";

$ordernumber= mysql_query($orderquery) or die ("Could not increase value");
//echo "order number: $ordernumber"; 
$maxvalue=intval(mysql_result($ordernumber,0,"max(orderNumber)"))+1;



$query="INSERT INTO Orders VALUES ($maxvalue, '$date','$ISBN', $quantity, '$branch', '$publisher','$customerid','$branchid','Requested')";

//echo "query: $query \n"; 
mysql_query($query) or die ("failed to add record");



//VALUES
//('$_POST[price]','$_POST[year]','$_POST[ISBN]', '$_POST[author]', '$_POST[subject]', '$_POST[publisher]', '$_POST[title]',
//'$_POST[quantity]')";

echo "1 record added";
mysql_close();
}


?> 

